package com.adtech.farmProducts.adapter;

import android.view.View;
import android.widget.TextView;

import com.adtech.common.widgets.recycler.RecyclerViewAdapter;
import com.adtech.farmProducts.R;
import com.adtech.farmProducts.model.FUserInfo;


/**
 * Author:  xiaocz.
 * Descr:  用户-列表
 */
public class UserListAdapter extends RecyclerViewAdapter<FUserInfo> {

    public UserListAdapter(AdapterListener<FUserInfo> adapterListener) {
        super(adapterListener);
    }

    @Override
    protected int getItemViewType(int position, FUserInfo data) {
        return R.layout.item_insert_list;
    }

    @Override
    protected ViewHolder<FUserInfo> getViewHolder(View view, int viewType) {
        return new InfoTypeViewHolder(view);
    }

    private static class InfoTypeViewHolder extends ViewHolder<FUserInfo> {

        private TextView tvCode, tvName, tvTime;

        public InfoTypeViewHolder(View itemView) {
            super(itemView);
            tvCode = itemView.findViewById(R.id.tv_code);
            tvName = itemView.findViewById(R.id.tv_name);
            tvTime = itemView.findViewById(R.id.tv_time);
        }

        @Override
        protected void onBind(FUserInfo data, int position) {
            tvCode.setText(data.getMobile());
            tvName.setText(data.getUserName());
            switch (data.getUserType()){
                case 1:
                    tvTime.setText("机构");
                    break;
                case 2:
                    tvTime.setText("普通员工");
                    break;
            }
        }

        @Override
        public boolean isNeedClick() {
            return true;
        }
    }
}